<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/common/hospital_token.jsp"%>
<%
    Integer labelId = input.getInt("label_id", -1);
    if (labelId == -1) {
        ErrcodeUtil.setErrcode(msg, ErrcodeUtil.FAILURE);
        Tools.encryptPrint(out, msg);
        return;
    }
    HospitalLabel hospitalLabel = LabelUtil.getHospitalLabelById(hospital, labelId);
    if (hospitalLabel == null) {
        msg.setErrcodeAndErrmsg(ErrcodeUtil.FAILURE, "标签不存在");
        Tools.encryptPrint(out, msg);
        return;
    }
    List<Map> countList = LabelUtil.getCountInLabel(hospital, labelId);
    if (countList != null && !countList.isEmpty()) {
        for (Map countMap : countList) {
            Integer _id = Tools.getInt(countMap.get("id") + "", -1);
            if (_id.equals(labelId)) {
                Integer count = Tools.getInt(countMap.get("count") + "", 0);
                if (count >= 1) {
                    msg.setErrcodeAndErrmsg(ErrcodeUtil.FAILURE, "不能删除非空的标签");
                    Tools.encryptPrint(out, msg);
                    return;
                }
                break;
            }
        }
    }
    int key = QBuilder.db("basedb").execHQL("update HospitalLabel hl set hl.status = " + ConstantUtil.STATUS_DISABLE + " where hl.id = " + labelId);
    if (key <= 0) {
        ErrcodeUtil.setErrcode(msg, ErrcodeUtil.FAILURE);
    } else {
        msg.setErrmsg("删除成功");
    }
    Tools.encryptPrint(out, msg);
%>
